file_name = input("请输入一个文件名: ")

with open(r'D:\Users\project\python\实验4 文件操作\\'+file_name,
          'r', encoding="UTF-8") as file:
    lines = file.readlines()
    lines_len = len(lines)
    words = []
    for line in lines:
        for ch in '!"#$%&()*+,./:;<=>?@[]^_{|}~\n':
            line = line.replace(ch, ' ')
        words.append(line.split())
    # print(f"{words}")
    count = 0
    for group in words:
        count += len(group)
    print(f"单词数: {count}\n行数: {lines_len}")
